<template>
  <entity-view
    :operator-type="operatorType"
    :model="beanInfo"
    @submit="submit"
    :rules="rules"
    ref="form"
  >

    <form-item
      label="支付通道"
      v-model="beanInfo.paramKey='aliPaySwitchFlag'?'支付宝直连':'其他方式'"
      prop="paramKey"
      disabled
    ></form-item>
    <form-item
      inputType = "select"
      label="网络类型"
      v-model="beanInfo.paramValue"
      prop="paramValue"
      :options="netTypeList"
      @change="value => selectedChange(value, 'netType')"
    ></form-item>
  </entity-view>
</template>
<script>
import EntityView from "../../../../components/common/entityView/EntityView.vue";
import FormItem from "../../../../components/common/entityView/FormItem.vue";
import moment from "moment";
moment.locale('zh-cn');

export default {
  name: "PayChannelNet",
  components: {
    EntityView,
    FormItem,
  },
  data: function () {
    return {
      operatorType: "edit",
      beanInfo: {
        paramKey:"",
        paramValue:"",
      },
      rules: {
        paramKey: [
          { required: true, message: "必填", trigger: "blur" },
        ],
        paramValue: [
          { required: true, message: "必填", trigger: "blur" },
        ],
      },
      netTypeList:[
        {value:"ZX",name:"专线"},
        {value:"NET",name:"互联网"},
      ],
    };
  },
  methods: {
    selectedChange(value,param) {
      this.beanInfo[param] = value;
    },
    async submit() {
      let res;
      switch (this.operatorType) {
        case "edit":
          res = await this.edit();
          break;
        default:
          break;
      }
      return res;
    },
    async edit() {
      const res = await this.$refs.form.validate();
      if (res) {
        const params = this.beanInfo;
        const res = await this.$post(
          "/admin/igas/PayChannelNet/edit",
          params
        );
        if (res.status === 200) {
          this.$message.success("保存成功！");
          return true;
        } else {
          this.$message.error(res.data.message);
          return false;
        }
      }
    },
    resetFields() {
      return this.$refs.form.resetFields();
    },
    setOperatorType(type) {
      this.operatorType = type;
    },
    setBeanInfo({...beanInfo}) {
      this.beanInfo = beanInfo;
    },
  },
};
</script>
